package com.yshebkb.sulp.domain;

import lombok.Data;

/**
 *
 * @author yshebkb
 * @date 2018/8/21
 */
@Data
public class RestResponse<T> {
    private boolean success;
    private T data;
    private Integer errorCode;
    private String errorMsg;

    private RestResponse(boolean success, T data) {
        this.success = success;
        this.data = data;
    }

    private RestResponse(boolean success, Integer errorCode, String errorMsg) {
        this.success = success;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public static <T> RestResponse success(T data) {
        return new RestResponse<>(true, data);
    }

    public static <T> RestResponse<T> failed(Integer errorCode, String errorMsg) {
        return new RestResponse<>(false, errorCode, errorMsg);
    }


}
